<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>hashBrowser</title>
</head>

<body>
    <div id="result"></div>
    <script>
        const hashBrowser = val => crypto.subtle.digest('SHA-256', new TextEncoder('utf-8').encode(val)).then(h => {
            const hexes = [];
            const view = new DataView(h);
            for (let i = 0; i < view.byteLength; i += 4) {
                hexes.push('00000000' + view.getUint32(i).toString(16).slice(-8));
            }
            return hexes.join("")
        })

        hashBrowser(
            JSON.stringify({
                a: 'a',
                b: [1, 2, 3, 4],
                foo: {
                    c: 'bar'
                }
            })
        ).then(v => {
            console.log(v);
            document.querySelector("#result").textContent = v;
        });
    </script>
</body>

</html>